package com.soul.dj.util.http;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.TextUtils;

import java.util.List;
import java.util.Map;

/**
 * @author
 * @ClassNmae AlertUitls
 * @create 2018-09-19 16:59
 **/
public class AlertDialogUitls {

    public static void alert(Activity activity,String title, String msg, String[] button,
                             DialogInterface.OnClickListener listener) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setCancelable(false);
        if (button != null) {
            builder.setPositiveButton(button[0], listener);
            if (button.length > 1) {
                builder.setNegativeButton(button[1], listener);
            }

            if (button.length > 2) {
                builder.setNeutralButton(button[2], listener);
            }
        }

        builder.setTitle(title);
        builder.setMessage(msg);
        builder.setIcon(android.R.drawable.ic_dialog_alert);

        builder.show();
    }

    public static void alertDialog(Activity activity, String title , List<Map<String,Object>> list, DialogInterface.OnClickListener listener) {

        final String[] array = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i).get("value").toString();
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        builder.setTitle(title);
        builder.setItems(array,listener);
        builder.setIcon(android.R.drawable.ic_dialog_map);


        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }
}
